Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cosmiconfig

Package Overview
Dependencies
Maintainers
4
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cosmiconfig

Find and load configuration from a package.json property, rc file, or CommonJS module

  • 7.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created

What is cosmiconfig?

The cosmiconfig npm package is a utility for finding and loading configuration from a variety of file formats and locations. It is commonly used in Node.js projects to create flexible configuration systems for tools and libraries.

What are cosmiconfig's main functionalities?

Searching for configuration files

This feature allows you to search for configuration files with a given name in various locations, including package.json properties, rc files, and regular JSON or YAML files.

const cosmiconfig = require('cosmiconfig');
const explorer = cosmiconfig('yourModuleName');
explorer.search()
  .then((result) => {
    const config = result ? result.config : {};
    // do something with config
  })
  .catch((error) => {
    // handle error
  });

Loading configuration files directly

This feature allows you to load a configuration file directly from a specified path, regardless of the file's format.

const cosmiconfig = require('cosmiconfig');
const explorer = cosmiconfig('yourModuleName');
explorer.load('/path/to/config').then((result) => {
  const config = result ? result.config : {};
  // do something with config
}).catch((error) => {
  // handle error
});

Creating a custom explorer

This feature allows you to create a custom explorer with specific search places and loaders, enabling you to define where and how configuration files should be found and interpreted.

const cosmiconfig = require('cosmiconfig');
const explorer = cosmiconfig('yourModuleName', {
  searchPlaces: ['custom.config.js', 'package.json'],
  loaders: {
    '.js': cosmiconfig.loadJs,
    '.json': cosmiconfig.loadJson
  }
});

Other packages similar to cosmiconfig

Keywords

FAQs

Package last updated on 12 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc